package com.xunk.equipment.config;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

import java.text.MessageFormat;

/**
 * @ProjectName: xunk
 * @Package: com.xunk.equipment.config
 * @ClassName: ConfigCompont
 * @Author: dongxiaoxin
 * @Description: 如影对接标准信息
 * @Date: 2021/3/26 9:31
 * @Version: 1.0
 */
@Data
@Component
@RefreshScope
public class EquipmentConfig {

    @Value("${iot.ruying.appId:}")
    public String appId;

    @Value("${iot.ruying.apiUrl:}")
    public String apiUrl;

    @Value("${iot.ruying.serectKey:}")
    public String serectKey;

    /**
     * 如影开放平台 产品信息接口链接
     * nacos 一直读不到这个配置，现在一直使用的是默认配置
     */
    private String specUrl;

    public String getSpecUrl() {
        return "https://iot-spec.knowin.com";
    }

    public String getDevicesUrl() {
        return this.apiUrl + "/api/v1/devices";
    }

    public String getDeviceUrl(String did) {
        return this.apiUrl + MessageFormat.format("/api/v1/device/{0}", did);
    }

    public String getDeviceUrl4Add() {
        return this.apiUrl + "/api/v1/devices";
    }

    public String getDeviceUrl4AddV2() {
        return this.apiUrl + "/api/v2/devices";
    }

    public String getShadowsUrl() {
        return this.apiUrl + "/api/v1/get-shadows";
    }

    public String getPropertiesUrl() {
        return this.apiUrl + "/api/v1/get-properties";
    }

    public String getSetPropertiesUrl() {
        return this.apiUrl + "/api/v1/set-properties";
    }

    public String getInvokeActionUrl() {
        return this.apiUrl + "/api/v1/invoke-actions";
    }

    public String getInteropCreate() {
        return this.apiUrl + "/api/v1/interop";
    }

    public String getInteropDelete(String interopId) {
        return this.apiUrl + MessageFormat.format("/api/v1/interop/{0}", interopId);
    }

    public String getInteropPut() {
        return this.apiUrl + "/api/v1/interop";
    }

    public String getInterops() {
        return this.apiUrl + "/api/v1/interops";
    }

    public String getInterop(String interopId) {
        return this.apiUrl + MessageFormat.format("/api/v1/interop/{0}", interopId);
    }

    public String getUpgrade(String did) {
        return this.apiUrl + MessageFormat.format("/api/v1/upgrade/{0}", did);
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public void setApiUrl(String apiUrl) {
        this.apiUrl = apiUrl;
    }

    public void setSerectKey(String serectKey) {
        this.serectKey = serectKey;
    }
}
